﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Forum.BLL.Group;
using Forum.Entity.Group;
using Frame.Lib.Utilities;
using Frame.Lib.Enums;


namespace Forum.Web.Admin.UForum.Group
{
    public partial class Edit : PageEdit
    {
        private GroupBO Group
        {
            get
            {
                return GroupBO.Instance<GroupBO>();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                WebUtil.BindListControlWithEnum(TypeID, typeof(GroupType));
                if (!string.IsNullOrEmpty(this.PKID))
                {
                    DispInfo();

                }
            }
        }

        private void DispInfo()
        {
            GroupInfo info = this.Group.GetInfo(this.PKID);

            EntityUtil.SetControl(pnlMain, info);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            bool flag = this.Group.ExistField(TableField.Name, Name.Text.Trim(), this.PKID);
            if (flag)
            {
                JSUtil.Alert("该组名已存在");
            }
            else
            {
                GroupInfo info = this.Group.GetInfo(PKID);

                EntityUtil.SetEntity(pnlMain, info);

                this.Group.Save(info);

                JSUtil.RefreshView();
            }

        }
    }
}